import 'dart:io';
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';

import 'api.dart';

Map<dynamic, String> nameOfMap = {};

String nameOf(dynamic obj) {
  if (!nameOfMap.containsKey(obj)) {
    String name = RegExp("(?<=Function[\\s]\\')[^\\']+")
        .firstMatch(obj.toString())
        .group(0);
    nameOfMap[obj] = name;
  }
  return nameOfMap[obj];
}

class ImmersionImpl implements ImmersionApi {
  static const MethodChannel _channel =
      const MethodChannel('vip.hsq168.plugin.flutter_immersion_bar');

  const ImmersionImpl();

  @override
  Future<bool> statusBarAlpha(double statusAlpha) {
    return _channel.invokeMethod<bool>(nameOf(statusBarAlpha), statusAlpha);
  }

  @override
  Future<bool> statusBarColor(Color color) {
    return _channel.invokeMethod<bool>(nameOf(statusBarColor), color.value);
  }

  @override
  Future<bool> statusBarDarkFont(bool isDarkFont, double statusAlpha) {
    return _channel.invokeMethod<bool>(
        nameOf(statusBarDarkFont), [isDarkFont, statusAlpha]);
  }
}
